package com.sec.android.app.myfiles.launch;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;

import com.sec.android.app.myfiles.activity.FileListActivity;
import com.sec.android.app.myfiles.fragment.search.SearchInputView;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.navigation.NavigationManager;

public class HandleSearchImp extends AbsHandleLaunchImp {

    @Override
    public boolean isMyJob(Intent intent) {
        return Intent.ACTION_SEARCH.equals(intent.getAction());
    }

    @Override
    public boolean _handleStart(int processId, Activity activity, Intent intent) {
        NavigationInfo info = NavigationManager.getInstance(processId).getCurInfo();
        if (info != null) {
            final String query = intent.getStringExtra(SearchManager.QUERY);

            SearchInputView searchView = null;
            if (activity instanceof FileListActivity) {
                searchView = ((FileListActivity) activity).getSearchView();
            }

            if (searchView != null) {
                searchView.clearFocus();
                searchView.setQuery(query, true);
            }
            return true;
        }
        return false;
    }
}
